/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.tool.web;

import lombok.Data;

/**
 * @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
 */
@Data
public class User {

    private String name;

    private Integer age;


    private static final String API_URL = "http://ip-api.com/json/";
    private static final String GAODE_API_URL = "https://restapi.amap.com/v3/ip?ip={ip}&output=json&key={key}";

//    public static void main(String[] args) {
//        try {
//            // 获取本机IP地址的地理位置信息
//            String ipAddress = "8.8.8.8";  // 可以替换为具体的IP地址或留空以获取本机IP
//            if (ipAddress == null || ipAddress.isEmpty()) {
//                ipAddress = getPublicIp();
//            }
//            String response = sendGetRequest(GAODE_API_URL.replace("{ip}", ipAddress).replace("{key}", "YOUR_AMAP_API_KEY"));
//
//            // 解析JSON响应
//            JsonObject jsonObject = new JsonParser(response).getAsJsonObject();
//            JsonObject addressComponent = jsonObject.getAsJsonObject("adcode").getAsJsonObject();
//
//            // 提取省市区信息
//            String province = addressComponent.get("province").getAsString();
//            String city = addressComponent.get("city").getAsString();
//            String district = addressComponent.get("district").getAsString();
//
//            System.out.println("Province: " + province);
//            System.out.println("City: " + city);
//            System.out.println("District: " + district);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    private static String getPublicIp() throws Exception {
//        String ipCheckUrl = "https://api.ipify.org";
//        return sendGetRequest(ipCheckUrl);
//    }
//
//    private static String sendGetRequest(String urlString) throws Exception {
//        URL url = new URL(urlString);
//        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//        connection.setRequestMethod("GET");
//
//        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//        String inputLine;
//        StringBuilder content = new StringBuilder();
//
//        while ((inputLine = in.readLine()) != null) {
//            content.append(inputLine);
//        }
//
//        in.close();
//        connection.disconnect();
//
//        return content.toString();
//    }

}
